In [17]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
z1 = 1 + 2j
z2 = 2 + 1j
def show_graph(imag_items, labels=None):
coords = tuple(map(lambda x: (x.real, x.imag), imag_items))
arrows = np.array(list(map(lambda x: (0,0,x[0],x[1]), coords)))
X,Y,U,V = zip(*arrows)
plt.figure(figsize=(8, 8))
ax = plt.gca()
ax.set_aspect('equal', adjustable='box')
ax.quiver(X,Y,U,V,angles='xy',scale_units='xy',scale=1)
max_number = 0
for c in coords:
max_number =max(max_number, max(map(abs, c)))
max_number += 1
ax.set_xlim([-max_number,max_number])
ax.set_ylim([-max_number,max_number])
for val in ax.spines.values():
val.set_position('center')
if labels is not None:
for coord, label in zip(coords, labels):
plt.annotate(label, xy=coord)
plt.draw()
plt.show()
show_graph((z1, z2), ('z1', 'z2'))
In [18]:
import cmath as cm
import math as m
z1 = 1 + 2j
z2 = 2 + 1j
print('abs z1:', abs(z1), '\nphase z1', (cm.phase(z1)/m.pi)*180)
print('abs z2:', abs(z2), '\nphase z2', (cm.phase(z2)/m.pi)*180)
In [19]:
show_graph((z1, z2, 3 + 3j), ('z1', 'z2', 'z1 + z2'))
show_graph((z1, z2, -1 + 1j), ('z1', 'z2', 'z1 - z2'))
In [20]:
def ctimes(z1, z2):
a = z1.real
b = z1.imag
c = z2.real
d = z2.imag
return (a*c - b*d) + (a*d + b*c)*1j
show_graph((z1, z2, ctimes(z1, z2)), ('z1', 'z2', 'z1 * z2'))
def cdiv(z1, z2):
a = z1.real
b = z1.imag
c = z2.real
d = z2.imag
return (a*c + b*d)/(c**2 + d**2) + ((b*c - a*d)/(c**2 + d**2))*1j
show_graph((z1, z2, cdiv(z1, z2)), ('z1', 'z2', 'z1 / z2'))
In [21]:
z1d = 1/z1
z2d = 1/z2
print(z1d, z2d)
show_graph((z1d, z2d, ctimes(z1d, z2d)), ('1/z1', '1/z2', '1/z1 * 1/z2'))
show_graph((z1d, z2d, cdiv(z1d, z2d)), ('1/z1', '1/z2', '(1/z1) / (1/z2)'))
complex getal | reële deel | imaginaire deel | absolute waarde | hoek in graden |
---|---|---|---|---|
$z_1 = 1 + 2j$ | 1 | 2 | 2.24 | 63.4 |
$z_2 = 2 + j$ | 2 | 1 | 2.24 | 26.6 |
$z_1 + z_2$ | 3 | 3 | $\sqrt{2*3^2} = 4.24$ | 45 |
$z_1 - z_2$ | -1 | 1 | $\sqrt{2}$ | 45 |
$z_1 \times z_2$ | 0 | 5.02 | $2.24 * 2.24 = 5.02$ | 90 |
$z_1 / z_2$ | $4/5$ | $3/5$ | $2.24/2.24 = 1$ | $63.4 - 26.6 = 36.8$ |
$1/z_1$ | $1/5$ | $-2/5$ | $1/2.24 = 0.45$ | -63.4 |
$1/z_2$ | $2/5$ | $-1/5$ | 0.45 | -26.6 |
complex getal | reële deel | imaginaire deel | absolute waarde | hoek in graden |
---|---|---|---|---|
$z_1 = 1 + 2j$ | 1 | 1 | $\sqrt{2}$ | 45 |
$z_2 = 2 + j$ | -1 | 1 | $\sqrt{2}$ | 135 |
$z_1 + z_2$ | 0 | 2 | 2 | 90 |
$z_1 - z_2$ | 2 | 0 | 2 | 0 |
$z_1 \times z_2$ | -2 | 0 | 2 | 180 |
$z_1 / z_2$ | 0 | -1 | 1 | -90 |
$1/z_1$ | $0.5$ | $-0.5$ | $1/\sqrt{2}$ | -45 |
$1/z_2$ | $-0.5$ | $-0.5$ | $1/\sqrt{2}$ | -135 |
z1: abs = $\sqrt{2}$, hoek=45
z2: abs = 0.781, hoek=50
In [22]:
z1 = m.sqrt(2)*m.e**0.7854j
z2 = 0.781*m.e**0.876j
print('real:', z1.real, ', img:', z1.imag)
print('real:', z2.real, ', img:', z2.imag)
$z1*z2$: abs=$0.781\sqrt{2}$, hoek=95
$z1/z2$: abs=$\sqrt{2}/0.781$, hoek=5
In [23]:
show_graph((z1, z2, z1*z2, z1/z2), ('z1', 'z2', 'z1 * z2', 'z1/z2'))